package com.huluobo.h3kotlinproject.login

import androidx.lifecycle.MutableLiveData
import com.huluobo.h3kotlinproject.data.UserBeanResult
import com.huluobo.h3kotlinproject.base.BaseRepo
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import okhttp3.RequestBody

/**
 *  Created by LC on 2023/10/17.
 */
open class LoginRepo : BaseRepo() {
   open fun login(body: RequestBody, success: MutableLiveData<UserBeanResult>, failed: MutableLiveData<String>) {
        getService().login(body).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<UserBeanResult> {
                override fun onSubscribe(d: Disposable) {
                }

                override fun onError(e: Throwable) {
                    failed.value = e.message
                }

                override fun onComplete() {
                }

                override fun onNext(t: UserBeanResult) {
                    success.value = t
                }
            })
    }
}